package com.flybutter.usagelab.broadcast;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.BatteryManager;

/**
 * 负责监听电池变化信息
 * @link <a>https://developer.android.com/training/monitoring-device-state/battery-monitoring</a>
 */
public class BatteryChangerReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        int status = intent.getIntExtra(BatteryManager.EXTRA_STATUS,-1);

        boolean isCharging = status == BatteryManager.BATTERY_STATUS_CHARGING ||
                status == BatteryManager.BATTERY_STATUS_FULL;
        //当前电量
        int level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL,-1);
        //总电量
        int scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE,-1);

    }
}